﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["login"] == null)
        {
            Response.Redirect("./login.aspx");
            return;
        }
        creatnewpoll();
        CreateOverPoll();
        CreateSendPoll();
    }


    private void CreateOverPoll()
    {
        string sql = string.Format("SELECT * FROM [pollution] WHERE [p_state]='{0}'", 1);
        ManageData md = new ManageData(util.DATACONNECTION);
        DataSet ds = md.ExecDS(sql);
        string strtext = string.Empty;
        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            strtext = "<ul>";
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                strtext += CreateList(
                    ds.Tables[0].Rows[i]["p_name"].ToString(),
                    i + 1,
                    ds.Tables[0].Rows[i]["p_lat"].ToString(),
                    ds.Tables[0].Rows[i]["p_lon"].ToString(),
                    "o"
                    );

            }

            strtext += "</ul>";

        }
        else
        {
            strtext = "没有相关信息";
        }

        overpoll.Text = strtext;

    }

    private void CreateSendPoll()
    {
        string sql = string.Format("SELECT * FROM [pollution] WHERE [p_state]='{0}' or [p_state]='{1}'", 2,3);
        ManageData md = new ManageData(util.DATACONNECTION);
        DataSet ds = md.ExecDS(sql);
        string strtext = string.Empty;
        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            strtext = "<ul>";
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                strtext += CreateList(
                    ds.Tables[0].Rows[i]["p_name"].ToString(),
                    i + 1,
                    ds.Tables[0].Rows[i]["p_lat"].ToString(),
                    ds.Tables[0].Rows[i]["p_lon"].ToString(),
                    "s"
                    );

            }

            strtext += "</ul>";

        }
        else
        {
            strtext = "没有相关信息";
        }

        sendpoll.Text = strtext;

    }

    private void creatnewpoll()
    {
        string sql = string.Format("SELECT * FROM [pollution] WHERE [p_state]='{0}'", 0);
        ManageData md = new ManageData(util.DATACONNECTION);
        DataSet ds = md.ExecDS(sql);
        string strtext = string.Empty;
        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            strtext = "<ul>";
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                strtext += CreateList(
                    ds.Tables[0].Rows[i]["p_name"].ToString(),
                    i + 1,
                    ds.Tables[0].Rows[i]["p_lat"].ToString(),
                    ds.Tables[0].Rows[i]["p_lon"].ToString(),
                    "n"
                    );

            }

            strtext += "</ul>";



        }
        else
        {
            strtext = "没有相关信息";
        }

        newpoll.Text = strtext;


    }

    private string CreateList(string name, int index, string strlat, string strlng,string strtype)
    {
        string ret = string.Empty;

        ret = string.Format(@"<li class='myli' style='display: block;'><div><a onclick='gotomark({0})'><img src='img/{1}.gif' align='absMiddle' /> {2}</a>
             <input type='hidden' id='plat{3}' name='plat{4}' value='{5}'>
             <input type='hidden' id='plng{6}' name='plng{7}' value='{8}'>
             </div></li>",
                         index,
                         index,
            name,
            strtype + index.ToString(),
            strtype + index.ToString(),
            strlat,
            strtype + index.ToString(),
            strtype + index.ToString(),
            strlng
            );

        return ret;
    }
}
